package cn.ctbu.xiaopeng.studentscoremanage.config;

import cn.ctbu.xiaopeng.studentscoremanage.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author xiaopeng
 * @version 1.0
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 配置静态资源路径
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置静态资源路径 "/static/**"
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/"); // 指向 src/main/resources/static/

     /*   // 如果需要其他路径，比如 "/templates/**"
        registry.addResourceHandler("/templates/**")
                .addResourceLocations("classpath:/templates/"); // 指向 src/main/resources/templates/*/
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**") // 拦截所有请求
                //不拦截的路径
                .excludePathPatterns("/login.html", // 排除登录请求
                        "/api/student/validate", //登录校验接口
                        "/admin/**","/component/**", "/config/**","/myjs/**",
                        "/css/**","/view/**");  //静态资源路径
    }
}
